# -*- coding: utf-8 -*-
"""
AI服务基类 - 支持多模型提供商
"""

from abc import ABC, abstractmethod
from typing import List, Dict, Any, Optional
from dataclasses import dataclass

@dataclass
class ModelConfig:
    """模型配置"""
    id: str
    name: str
    provider: str
    api_key: str = ""
    base_url: str = ""
    max_tokens: int = 1000
    temperature: float = 0.7
    enabled: bool = True

class AIServiceBase(ABC):
    """AI服务基类"""
    
    def __init__(self, config: ModelConfig):
        self.config = config
        self._client = None
    
    @abstractmethod
    def chat_completion(self, messages: List[Dict[str, str]]) -> str:
        """同步对话完成"""
        pass
    
    @abstractmethod
    async def async_chat_completion(self, messages: List[Dict[str, str]]) -> str:
        """异步对话完成"""
        pass
    
    @abstractmethod
    def test_connection(self) -> bool:
        """测试API连接"""
        pass
    
    @property
    def model_info(self) -> Dict[str, Any]:
        """获取模型信息"""
        return {
            "id": self.config.id,
            "name": self.config.name,
            "provider": self.config.provider,
            "enabled": self.config.enabled
        }